<template>
  <div class="main">
    <top-bar></top-bar>
    <div class="main-mains w90">
      <div class="main-mains-l">
        <router-link to="/main">
          <div class="main-mains-l-return">
            <span>←</span>
            返回首页
          </div>
        </router-link>
        <div class="active">合理化建议</div>
      </div>
      <div class="main-mains-r">
        <div class="main-mains-table" v-show="dataFlag">
          <div class="main-mains-list">
            <ul>
              <li v-for="(item,index) in dataList" :key="index">
                <router-link :to="'/suggestdetails/' + item.id">{{item.context}} <span class="time">{{item.createtime}}</span></router-link>
              </li>
            </ul>
          </div>
          <div class="main-pages">
            <el-pagination
              background
              layout="prev, pager, next"
              :page-size="15"
              @current-change="changePage"
              :total="totalNum"
            ></el-pagination>
          </div>
          <div class="down-excle" v-show="dataFlag" @click="downExcle()">下载Excel表格</div>
        </div>
        <div class="main-mains-none" v-show="!dataFlag">
          <img src="../../../static/images/none.png" alt>
          <br>
          <div>暂无记录</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "../public/top";
export default {
  components: {
    topBar
  },
  data() {
    return {
      dataList: [],
      pageNum: 1,
      dataFlag: true,
      totalNum: 1,
      pages: 1
    };
  },
  methods: {
    downExcle() {
      window.open(
        this.urls +
          "/membership/export" +
          "?code=advise" +
          "&PageSize=15&startPage=" +
          this.pages
      );
    },
    changePage(val) {
      this.pages = val;
      this.getData();
    },
    getData() {
      let _this = this;
      _this.dataFlag = false;
      _this
        .$http({
          url:
            _this.urls +
            "/membership/list.do" +
            "?code=advise&PageSize=15&startPage=" +
            _this.pages,
          method: "get"
        })
        .then(function(res) {
          let data = res.data;
          if (data.status == "success") {
            _this.dataList = data.data;
            _this.dataList = data.data.list;
            _this.totalNum = data.data.total;
            if (data.data.total) {
              _this.dataFlag = true;
            }
          } else {
            _this.$message({
              showClose: true,
              message: data.msg,
              type: "error"
            });
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang="less" scoped>
@import "suggest.less";
</style>

